package com.likeycy.my;

import com.likeycy.my.file.FileInfo;
import com.likeycy.my.file.Files;
import com.likeycy.my.map.MyMap;
import com.likeycy.my.map.MyTreeMap;
import com.likeycy.my.set.MySet;
import com.likeycy.my.set.MyTreeSet;

/**
 * @ClassName: TestMyMap
 * @Description: 测试实现的map
 * @Author: sodagreen
 * @Date: 2021/3/25 2:49
 * @Version: 1.0
 */
public class TestMyMap {

    static void testMyTreeMap() {
        MyMap<String, Integer> map = new MyTreeMap<>();
        map.put("class", 2);
        map.put("public", 5);
        map.put("zhouJieLun", 40);
        map.put("caiYiLin", 38);
        map.put("yangChaoYue", 25);
        map.put("public", 8);
        map.put("c", 13);
        map.put("a", 11);
        map.put("b", 12);

        map.traversal(new MyMap.Visitor<String, Integer>() {
            @Override
            public boolean visit(String key, Integer value) {
                System.out.println(key + "_" + value);
                return false;
            }
        });
    }

    /**
     * 读取文件内的单词数量去重
     */
    public static void test2() {
        FileInfo fileInfo = Files.read("D:\\soft\\Java\\openjdk-1.8\\src\\java\\util\\concurrent"
                , new String[]{"java"});
        System.out.println("文件数量：" + fileInfo.getFiles());
        System.out.println("代码行数：" + fileInfo.getLines());
        String[] words = fileInfo.words();
        System.out.println("单词总数：" + words.length);

        MyMap<String, Integer> map = new MyTreeMap<>();
        for (int i = 0; i < words.length; i++) {
            Integer value = map.get(words[i]);
            value = (value == null) ? 1 : (value + 1);
            map.put(words[i], value);
        }
        System.out.println(map.size());

        map.traversal(new MyMap.Visitor<String, Integer>() {
            @Override
            public boolean visit(String key, Integer value) {
                System.out.println(key + "_" + value);
                return false;
            }
        });
    }

    static void test3() {
        MySet<String> set = new MyTreeSet<>();
        set.add("c");
        set.add("a");
        set.add("b");
        set.add("c");
        set.add("a");

        set.traversal(new MySet.Visitor<String>() {
            @Override
            public boolean visit(String element) {
                System.out.println(element);
                return false;
            }
        });
    }

    public static void main(String[] args) {
//        testMyTreeMap();
        test3();
    }
}
